﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class CustomerView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.LoadProjects();
    }
    protected void Click_Logout(object sender, EventArgs e)
    {
        System.Web.Security.FormsAuthentication.SignOut();
        Response.Redirect("Login.aspx");
    }

    protected void LoadProjects()
    {
        TimeTrackerDataContext context = new TimeTrackerDataContext();

        MembershipUser user = Membership.GetUser();

        var company = (from cu in context.CompanyUsers
                        where cu.UserId == (Guid)user.ProviderUserKey
                        select cu).Single();

        this.LinqDataSourceProjects.WhereParameters["customerID"].DefaultValue = company.CustomerId.ToString();
        this.DataListProject.DataBind();

    }

    protected string GetTotalTime(int id)
    {
        TimeTrackerDataContext context = new TimeTrackerDataContext();
        decimal total = 0;

        var entries = (from te in context.timeEntries
                       where te.projectID == id
                       select te);
        if (entries.Count() > 0 )
            total = entries.Sum(t => t.timeInterval);

        return total.ToString();
    }

}